<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="时间范围">
          <el-date-picker
              v-model="value1"
              type="datetimerange"
              value-format="yyyy-MM-dd HH:mm:ss"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="handleDateChange">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="地区:" prop="areaId">-->
<!--          <el-cascader class="col"-->
<!--                       placeholder="可输入地区名称进行搜索"-->
<!--                       v-model="listPram.areaId"-->
<!--                       :options="options"-->
<!--                       clearable-->
<!--                       :props="{ expandTrigger: 'hover' }"-->
<!--                       filterable-->
<!--                       @change="handleChange"></el-cascader>-->
<!--        </el-form-item>-->
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="formLoading" :data="listData.records" style="width: 100%" size="small" highlight-current-row>

        <template v-if="type==1||type==2||type==3">
          <el-table-column prop="id" label="ID" min-width="50"/>
          <el-table-column prop="nickName" label="用户" min-width="80"/>
          <el-table-column prop="phone" label="手机号" min-width="100"/>
          <el-table-column prop="typeName" label="类型" min-width="150"/>
          <el-table-column prop="name" label="描述" min-width="150"/>
          <el-table-column v-if="type==1||type==2"  label="益联券" min-width="100">
            <template slot-scope="scope">
              <span>{{Math.abs(scope.row.voucherAmount)}}券</span>
            </template>
          </el-table-column>
          <el-table-column v-if="type==3"  label="手续费" min-width="100">
            <template slot-scope="scope">
              <span>{{scope.row.fees}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="记录时间" min-width="100"/>
        </template>
        <template v-if="type==4||type==5||type==6">
          <el-table-column prop="id" label="ID" min-width="50"/>
          <el-table-column prop="serialNumber" label="流水号" min-width="150"/>
          <el-table-column prop="createTime" label="变动时间" min-width="100"/>
          <el-table-column prop="pumpingType" label="抽成券值" min-width="100">
            <template slot-scope="scope">
              <span v-if="type==4">{{ scope.row.plartformVoucher }}</span>
              <span v-if="type==5">{{ scope.row.cityVoucher }}</span>
              <span v-if="type==6">{{ scope.row.areaVoucher }}</span>
            </template>
          </el-table-column>
        </template>
        <el-table-column label="操作" min-width="80" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button  size="mini" type="primary" @click="jumpNewPage(scope.row.phone)"  >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[10,20,50,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import {
  transferDataList
} from "@/api/dashboard";
import {optionsList} from "@/api/business";

export default {
  components: {},
  props: {
    type: {
      default: null
    }
  },
  data() {
    return {
      value1:'',
      formLoading: false,
      listData: {records: [], total: 0},
      value: [],
      options: [{
        value: '',
        label: '',
        children: [{
          value: '',
          label: '',
          children: [{
            value: '',
            label: ''
          }]
        }]
      }],
      listPram: {
        page: 1,
        limit: 10,
        areaId:'',
        startTime: '',
        endTime: '',
        type:0
      },
    }
  },
  mounted() {
      if(this.type)
      {
        this.listPram.type=this.type
      }
      this.getList();
    this.getOptions();
  },
  methods: {
    getOptions() {
      optionsList().then(res => {
        this.options = res
      })
    },
    handleChange(value) {
      this.listPram.areaId = value[2]
    },
    jumpNewPage(mobile) {

     if (this.type == 1||this.type==2||this.type==3)
      {
        let routeLogin = this.$router.resolve({
          path: "/financial/circulation",
          query: {
            keyword: `${mobile}`
          }
        });
        window.open(routeLogin.href, '_blank');
        //如果希望在新页面中打开超链接，则需要设置跳转方式为  _blank
      }
      else if (this.type == 4||this.type==5||this.type==6)
      {
        let routeLogin = this.$router.resolve({
          path: "/financial/CommissionRecord"
        });
        window.open(routeLogin.href, '_blank');
        //如果希望在新页面中打开超链接，则需要设置跳转方式为  _blank
      }
    },
    handleDateChange(value) {
      this.listPram.startTime = value[0];
      this.listPram.endTime = value[1];
    },
    getList() {
      transferDataList(this.listPram).then(res => {
          this.listData = res
        }).finally(() => {
          this.formLoading = false;
        })

    },
    close() {
      this.$emit('hideEditDialog')
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    resetQuery() {
      this.value1=''
      this.listPram.page = 1;
      this.listPram.areaId = null;
      this.listPram.limit = 10;
      this.listPram.endTime = '';
      this.listPram.startTime = '';

      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep {
  .el-upload {
  }
}

.img {
  width: 80px;
  height: 80px;
  border-radius: 100px;
}
</style>
